package us.yesor.atlast;

import us.yesor.atlast.R;
import us.yesor.atlast.R.layout;
import us.yesor.atlast.R.menu;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class ItemManagementActivity extends ListActivity
{
    private TextView selectedItemTestTextView;
    
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item_management);
        this.setupListView();
        
        this.selectedItemTestTextView = (TextView) this.findViewById(R.id.selectedItemTestTextView);
    }

    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.activity_item_management, menu);
        return true;
    }
    
    private void setupListView()
    {
        String[] sampleItems = new String[]{"hamster", "dog", "cat"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, sampleItems);
        this.setListAdapter(adapter);
    }
    
    protected void onListItemClick(ListView l, View v, int position, long id)
    {
        this.selectedItemTestTextView.setText(
                this.getListView().getItemAtPosition(position).toString());
    }
    
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
            case R.id.collections_menu_item:
                Intent intent = new Intent(this, CollectionManagementActivity.class);
                this.startActivity(intent);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
